<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;

class Operationlog extends Controller
{
    public function getOperationLogList()
    {



        $data = request()->post();
        $page = isset($data['page']) ? intval($data['page']) : 1;
        $limit = isset($data['limit']) ? intval($data['limit']) : 10;
        
        $map = [];

        
        if (isset($data['actor']) && !empty($data['actor'])) {
            $map['actor'] = ['=', $data['actor']];
        }
        
        if (isset($data['object']) && $data['object'] !== '') {
            $map['object'] =  array("like", "%".$data['object']."%");
        }

        if (isset($data['operation_type']) && $data['operation_type'] !== '') {
            $map['operation_type'] =  array("=", $data['operation_type']);
        }



        if (isset($data['start_time']) && $data['start_time'] !== '') {
            $map['create_time'] =  array("between", [$data['start_time'], $data['end_time']]);
        }
        
        // 获取总数
        $count = Db::table('zstp_sys_log')
            ->where($map)
            ->count();
            
        // 获取分页数据
        $list = Db::table('zstp_sys_log')
            ->where($map)
            ->page($page, $limit)
            ->order('create_time desc')
            ->select();
            
        return json([
            'code' => 200,
            'message' => '获取成功',
            'data' => [
                'totalCount' => $count,
                'resultList' => $list,
                'page' => $page,
                'limit' => $limit
            ]
        ]);
       
    }
}